// 由于找不到 '@/utils/request' 模块，此处假设使用 axios 作为请求库，实际项目中请修正导入路径或实现该模块
import axios from 'axios';
const request = axios;
// 由于找不到 '@/api/common' 模块，这里假设 `PageParams` 和 `PageResult` 是通用分页类型，
// 需根据实际项目情况在合适位置定义这些类型，或者修正导入路径。以下为模拟定义示例，实际使用时请替换。
interface PageParams {
  pageNo?: number;
  pageSize?: number;
}

interface PageResult<T> {
  list: T[];
  total: number;
}

/** 用户阅读历史 API */
export interface UserReadingHistoryApi {
  /** 分页获取用户阅读历史列表 */
  getReadingHistoryPage(params: PageParams & {
    userId?: number
    bookId?: number
    startTime?: string
    endTime?: string
  }): Promise<PageResult<UserReadingHistory>>

  /** 获取用户阅读历史详情 */
  getReadingHistory(id: number): Promise<UserReadingHistory>

  /** 创建用户阅读历史 */
  createReadingHistory(data: UserReadingHistory): Promise<void>

  /** 更新用户阅读历史 */
  updateReadingHistory(data: UserReadingHistory): Promise<void>

  /** 删除用户阅读历史 */
  deleteReadingHistory(id: number): Promise<void>

  /** 批量删除用户阅读历史 */
  deleteReadingHistoryBatch(ids: number[]): Promise<void>
}

/** 用户阅读历史实体 */
export interface UserReadingHistory {
  id: number
  userId: number
  bookId: number
  bookTitle: string
  readTime: number
  lastReadPosition: number
  finished: boolean
  createTime: string
  updateTime: string
}

const userReadingHistoryApi: UserReadingHistoryApi = {
  getReadingHistoryPage: (params) => request.get('/pickbook/admin/user-reading-history/page', { params }),
  getReadingHistory: (id) => request.get(`/pickbook/admin/user-reading-history/${id}`),
  createReadingHistory: (data) => request.post('/pickbook/admin/user-reading-history', data),
  updateReadingHistory: (data) => request.put('/pickbook/admin/user-reading-history', data),
  deleteReadingHistory: (id) => request.delete(`/pickbook/admin/user-reading-history/${id}`),
  deleteReadingHistoryBatch: (ids) => request.delete('/pickbook/admin/user-reading-history/batch', { data: ids })
}

export default userReadingHistoryApi